import api from '../../../http/api';
import date from '@/src/utils/date.js';
import detectEthereumProvider from '@metamask/detect-provider';
import CustomBackBar from '@/components/CustomBackBar/CustomBackBar.vue';
export default {
	components: {CustomBackBar},
	data() {
		return {
			loading: true,
			records: [],
			filterStatus: 'all',
			filterDate: 'all',
			currHuobi: localStorage.getItem('HUOBI') || 'USDT'
		}
	},
	computed: {
		// 过滤后的记录
		filteredRecords() {
			let filtered = this.records;

			// 按状态过滤
			if (this.filterStatus !== 'all') {
				filtered = filtered.filter(r => r.status == this.filterStatus);
			}

			// 按时间过滤 (这里简化处理，实际应根据日期计算)
			if (this.filterDate !== 'all') {
				// 实际项目中应根据日期进行过滤
				filtered = filtered; // 这里保留所有记录作为示例
			}

			return filtered;
		},

	},
	created() {
		// 模拟API请求
		this.fetchRecords();
	},
	methods: {
		async fetchRecords() {
			this.loading = true;
			
			const provider = await detectEthereumProvider();
			
			const accounts = await provider.request({
				method: 'eth_accounts'
			});
			const userSettings = JSON.parse(localStorage.getItem('userSettings'))
			
			api.incomeRecord({
				address:accounts[0],
				chaintype:userSettings.chainType,
				cointype:userSettings.cointype
			}).then(res=>{
				if(res.code==1){
					this.records = res.data
				}else{
					ni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			}).catch(err => {
				
			}).finally(() => {
				this.loading = false;
			})
		},

		// 获取状态对应的CSS类
		getStatusClass(status) {
			switch (status) {
				case 0:
					return 'pending';
				case 1:
					return 'approved';
				case 2:
					return 'rejected';
				default:
					return '';
			}
		},

		// 获取状态文本
		getStatusText(status) {
			switch (status) {
				case 0:
					return '审核中';
				case 1:
					return '通过';
				case 2:
					return '已拒绝';
				default:
					return '';
			}
		},

		// 获取状态图标
		getStatusIcon(status) {
			switch (status) {
				case 0:
					return 'fas fa-check-circle';
				case 1:
					return 'fas fa-hourglass-half';
				case 2:
					return 'fas fa-times-circle';
				default:
					return '';
			}
		}
	}
}